package com.zm.springcloudsentinel.util;

import com.alibaba.csp.sentinel.slots.block.authority.AuthorityException;
import com.alibaba.csp.sentinel.slots.block.degrade.DegradeException;
import com.alibaba.csp.sentinel.slots.block.flow.FlowException;
import com.alibaba.csp.sentinel.slots.block.flow.param.ParamFlowException;

/**
 * 根据异常类型返回异常类型返回不同响应
 */
public class SentinelExceptionUtil {

    public static String exceptionType(Exception e){
        String msg="未知异常";
        if (e instanceof FlowException){
            msg="请求限流";
        } else if (e instanceof ParamFlowException) {
            msg="热点参数限流";
        } else if (e instanceof DegradeException) {
            msg="请求降级";
        } else if (e instanceof AuthorityException) {
            msg="无权访问";
        }
        return msg;

    }

}
